package jzqb.config;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.CacheControl;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.concurrent.TimeUnit;

@Component
public class SysConfig implements WebMvcConfigurer {
   /* @Autowired
    private TokenInterceptor interceptor;*/

    /*资源放行*/
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /*放行swagger*/
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/")
                .setCacheControl(CacheControl.maxAge(1, TimeUnit.HOURS).cachePublic());
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/")
                .setCacheControl(CacheControl.maxAge(1, TimeUnit.HOURS).cachePublic());
        /*放行项目中的静态资源*/
        registry.addResourceHandler("/static/**")
                .addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/static/");
    }

    /*跨域*/
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")//放行的地址
                .allowedHeaders("*")  //请求头
                .allowedMethods("*") //请求方法
                .allowedOrigins("*")//域名
                .allowCredentials(true)// 是否允许证书 不再默认开启
                .maxAge(3600);
    }

//    /*token拦截器的放行列表*/
//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(interceptor).addPathPatterns("/**")
//                .excludePathPatterns("/**/*.*")
//                .excludePathPatterns("/")
//                .excludePathPatterns("/shareVideo", "/shareVideo/")
//                .excludePathPatterns("/admin", "/admin/")
//                .excludePathPatterns("/adminUserInfo/login") //前后台登录接口
//                .excludePathPatterns("/adminUserInfo/initPwd")//初次登录重置密码接口
//                .excludePathPatterns("/ueditor/**")
//                .excludePathPatterns("/adminUserInfo/initJson")
//                .excludePathPatterns("/admin/tree/**")
//                .excludePathPatterns("/adminLog/exportStandardStatistics")//xt的资源日志
//                .excludePathPatterns("/adminQBZS/getTemplate")//xt的批量下载模板
//                .excludePathPatterns("/adminUserInfo/getTemplate")//用户模块-下载批量导入用户的模板
//                .excludePathPatterns("/adminDepartmentInfo/getTemplate")//部门模块-下载批量导入部门的模板
//                .excludePathPatterns("/adminLog/exportViewDownloadLog")//导出浏览下载日志
//                .excludePathPatterns("/adminLog/exportLoginLog")//导出登录日志
//                .excludePathPatterns("/adminLog/exportMonitorLog")          //导出管理员关键操作
//                .excludePathPatterns("/qbbk/getQBBKCover")//获取情报百科封面
//                .excludePathPatterns("/result/getFileResult")//获取情报百科封面
//                .excludePathPatterns("/jsyy/getPictureResource")//获取情报百科封面
//                .excludePathPatterns("/jsyy/getVideoResource")//获取情报百科封面
//                .excludePathPatterns("/ztj/getPictureResource")//获取专题集封面
//                .excludePathPatterns("/ztwx/getClassFy");//获取专题文献TypeBo
//    }
}
